package com.jyh.supermark.dao.impl;

import com.jyh.db.BaseDAO;
import com.jyh.supermark.dao.UserDao;
import com.jyh.supermark.domain.User;
import java.util.List;

public class UserDaoImpl implements UserDao {
    @Override
    public User find(String name) {
        String sql="select * from user where username=?";
        List<User> userList = BaseDAO.selectMultipleRow(sql, User.class, name);
        if (userList.size()!=0){
            return userList.get(0);
        }
        return null;
    }

    @Override
    public int register(User user) {
        String sql="insert INTO user value(?,?,?,?)";
        int count = BaseDAO.insertOneRow(sql, user.getUsername(), user.getPassword(), user.getOthername(), user.getAge());
        return count;
    }

    public User login(User user) {
        String sql="select * from user where username=? and password=?";
        List<User> userList = BaseDAO.selectMultipleRow(sql, User.class, user.getUsername(), user.getPassword());
        if (userList.size()>0){
            User user1 = userList.get(0);
            return user1;
        }
        return null;
    }
}
